<?php 
include("db/connect.php");
include("prename.php");
if(@$_POST["type"]==1){
	$sqldeleteemployee="delete from employee where emp_id='".@$_POST["temp"]."'";
	$querydelete=mysql_query($sqldeleteemployee);
	}
	else if(@$_POST["type"]==3){
		$sqlupdate="update employee set emp_title='".@$_POST["emp_title"]."',emp_name='".@$_POST["emp_name"]."',emp_lastname='".@$_POST["emp_lastname"]."',emp_addr='".@$_POST["emp_addr"]."',province_id='".@$_POST["province_id"]."',amphur_id='".@$_POST["amphur_id"]."',tambol_id='".@$_POST["tambol_id"]."',emp_postal='".@$_POST["emp_postal"]."',emp_tel='".@$_POST["emp_tel"]."',emp_mail='".@$_POST["emp_mail"]."' where emp_id='".@$_POST["temp"]."'";
		$queryupdateemployee=mysql_query($sqlupdate);
		}
		$sqlselectemployee="select * from employee,province,amphur,tambol";
		$sqlselectemployee.=" where employee.province_id=province.province_id and";
		$sqlselectemployee.=" employee.amphur_id=amphur.amphur_id and";
		$sqlselectemployee.=" employee.tambol_id=tambol.tambol_id";
		$sqlselectemployee.=" group by emp_id";
		$queryselectemployee=mysql_query($sqlselectemployee);
?>
<table width="100%" height="132" border="1">
  <tr>
  	<th width="25%">ชื่อ-นามสกุล</th>
    <th width="40%">ที่อยู่</th>
    <th width="13%">รหัสไปรษณีย์</th>
    <th width="13%">เบอร์โทรศัพท์</th>
    <th width="7%">Email</th>
    <th width="7%">แก้ไข</th>
    <th width="6%">ลบ</th>
  </tr>
  <?php 
  while($resultemployee=@mysql_fetch_array($queryselectemployee)){
  ?>
  <tr>
  	<td><?php echo prename($resultemployee["emp_title"])." ".$resultemployee["emp_name"]." ".$resultemployee["emp_lastname"]?></td>
    <td><?php echo $resultemployee["emp_addr"]." ".$resultemployee["tambol_name"]." ".$resultemployee["amphur_name"]." ".$resultemployee["province_name"]?></td>
    <td><?php echo $resultemployee["emp_postal"]?></td>
    <td><?php echo $resultemployee["emp_tel"]?></td>
    <td><?php echo $resultemployee["emp_mail"]?></td>
   <td><a href="Javascript:ajaxmanage(2,<?php echo $resultemployee["emp_id"];?>);">แก้ไข</a></td>
    <td><a href="Javascript:ajaxmanage(1,<?php echo $resultemployee["emp_id"];?>);" onclick="return window.confirm('ต้องการลบใช่ไหม')">ลบ</a></td>
  </tr>
  <?php }?>
</table>
<script>
 $(function() {
		/* For zebra striping */
        $("table tr:nth-child(odd)").addClass("odd-row");
		/* For cell text alignment */
		$("table td:first-child, table th:first-child").addClass("first");
		/* For removing the last border */
		$("table td:last-child, table th:last-child").addClass("last");
});</script>